'''
Created on 2013-03-13

@author: Nich
'''
from graph.graphnodes import *
from collections import defaultdict
#|0|   ____
#|||  / 0  \
#|||_// | \ \   N
#|0-_0 -0- 0| W   E
#||| \\ | / /   S
#|||  \_0__/
#|0| 

#This is just the display graph. The graph that allows from movement needs to be distinct. 
#In that case, do we need the links at all?




hallway = Room("gryffindore_corridore")
hall_n = hallway.add_location("north")
hall_m = hallway.add_location("middle")
hall_s = hallway.add_location("south")

Link(hall_n, hall_m)
Link(hall_m, hall_s)


gryffindore_common_room = Room("gryffindore_common_room")

gcr_n = gryffindore_common_room.add_location("north")
gcr_e = gryffindore_common_room.add_location("east")
gcr_w = gryffindore_common_room.add_location("west")
gcr_s = gryffindore_common_room.add_location("south")
gcr_m = gryffindore_common_room.add_location("middle")

Link(gcr_n, gcr_m)
Link(gcr_n, gcr_e)
Link(gcr_n, gcr_w)
Link(gcr_e, gcr_m)
Link(gcr_e, gcr_s)
Link(gcr_w, gcr_m)
Link(gcr_w, gcr_s)
Link(gcr_s, gcr_m)

gcr_n.add_object(Object("chair1", "chair1", "chair"))
gcr_w.add_object(Object("chair1", "chair1", "chair"))

def aggregate_by_contents(start_loc):
    contents = defaultdict(set)
    for loc in walk_tree_bf(start_loc):
        if not loc.contents:
            contents["nothing"].add(loc)
        else:
            print(loc.contents)
            for _, c in loc.contents.items():
                contents[c.type].add(loc)
    return contents

def display_room(start_loc):
    #aggregate by contents
    contents = aggregate_by_contents(start_loc)
    
    for k, v in contents.items():
        print(k +", "+(str(v)))
    
        


if __name__ == '__main__':
    display_room(gcr_n)
    
    